﻿// <copyright file="EsriPoint.cs" company="City of Portland, BES-ASM">
// </copyright>
// <summary>Implementation of EsriPoint class.</summary>

namespace BESASM.EMGAATS.Arc
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using BESASM.EMGAATS.BusinessClasses;
  using ESRI.ArcGIS.esriSystem;
  using ESRI.ArcGIS.Geometry;

  /// <summary>
  /// An implementation of IPoint that wraps an ESRI Point object.
  /// </summary>
  public class EsriPoint : BusinessClasses.IPoint
  {
    private ESRI.ArcGIS.Geometry.IPoint esriPoint;

    /// <summary>
    /// Initializes a new instance of the EsriPoint class.
    /// </summary>
    /// <param name="point">The ESRI point this class will wrap.</param>
    public EsriPoint(ESRI.ArcGIS.Geometry.IPoint point)
    {
      this.esriPoint = point;
    }

    /// <summary>
    /// Gets the ESRI point this object wraps.
    /// </summary>
    public ESRI.ArcGIS.Geometry.IPoint Point
    {
      get
      {
        return this.esriPoint;
      }
    }

    #region IPoint Members

    /// <summary>
    /// Gets or sets the x-coordinate
    /// </summary>
    public double X
    {
      get
      {
        return this.esriPoint.X;
      }

      set
      {
        this.esriPoint.X = value;
      }
    }

    /// <summary>
    /// Gets or sets the y-coordinate
    /// </summary>
    public double Y
    {
      get
      {
        return this.esriPoint.Y;
      }

      set
      {
        this.esriPoint.Y = value;
      }
    }

    /// <summary>
    /// Returns a value indicating if this point has the same coordinates as the given point.
    /// </summary>
    /// <param name="point">The point to compare to this one.</param>
    /// <returns>True if the points are the same, otherwise false.</returns>
    public bool IsEquivalentTo(BusinessClasses.IPoint point)
    {
      if (point == null)
      {
        return false;
      }

      return this.X == point.X && this.Y == point.Y;
    }

    /// <summary>
    /// Creates a new point that is a copy of the current instance.
    /// </summary>
    /// <returns>A new object that is a copy of this instance.</returns>
    public object Clone()
    {
      IClone pointClone = ((IClone)this.esriPoint).Clone();
      return new EsriPoint((ESRI.ArcGIS.Geometry.IPoint)pointClone);
    }

    #endregion
  }
}
